package com.cypher.encryptionanddecryption.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.alibaba.fastjson.JSONObject;
import com.cypher.encryptionanddecryption.R;
import com.cypher.encryptionanddecryption.activity.BluetoothCommunicationActivity;
import com.cypher.encryptionanddecryption.activity.MainActivity;
import com.cypher.encryptionanddecryption.adapter.CommunicationAdapter;
import com.cypher.encryptionanddecryption.bean.CommunicationBean;
import com.cypher.encryptionanddecryption.bluetooth.BluetoothGattManager;
import com.cypher.encryptionanddecryption.bluetooth.BluetoothManagerSingleton;
import com.cypher.encryptionanddecryption.bluetooth.ExpandBroadcastReceiver;
import com.cypher.encryptionanddecryption.dao.CommunicationDao;
import com.cypher.encryptionanddecryption.dao.impl.CommunicationDaoImpl;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 设置界面
 * @author: 古霸天
 * @date: 2020/11/16
 */
public class SettingsFragment extends Fragment {

    private MainActivity mainActivity;
    private RadioGroup protocolGroup;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_settings, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        mainActivity = (MainActivity) BluetoothManagerSingleton.getInstance().getActivity();
        initRadioBtn(view);
    }

    private void initRadioBtn(View view) {
        protocolGroup = view.findViewById(R.id.protocol_group);

        /**
         * 按钮组选中状态改变
         */
        protocolGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
            switch (checkedId) {
                case R.id.set_2_5_protocol:
                    mainActivity.setProtocolTitle("2.5协议");
                    mainActivity.setProtocolId(0);
                    break;
                case R.id.set_kunlun_protocol:
                    mainActivity.setProtocolTitle("昆仑协议");
                    mainActivity.setProtocolId(1);
                    break;
                case R.id.set_JinRan_protocol:
                    mainActivity.setProtocolTitle("津燃协议");
                    mainActivity.setProtocolId(2);
                    break;
            }
        });
    }

}
